<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <div id ="container"> </div>

    <script>
        function changeColor(time,color){
          return new Promise(resolve=>setTimeout(()=>resolve(document.body.style['backgroundColor']=color),time));
        }

       async function  fn(){
           await changeColor(3000,'red');
           console.log(currentTime());
           await changeColor(2000,'green');
           console.log(currentTime());
           await changeColor(1000,'yellow');
           console.log(currentTime());
            await fn();

        }
        fn();

        function some(param){
            return param<10?'0'+param:param;
        }

        function currentTime(){
            var d=new Date();
            var year=some(d.getFullYear());
            var mon=some(d.getMonth()+1);
            var day=some(d.getDate());
            var hour=some(d.getHours());
            var min=some(d.getHours());
            var sec=some(d.getSeconds());
            return year+':'+mon+':'+day+':'+hour+':'+min+':'+sec;


        }


    </script>
</body>

</html>